import type { PageParam, PageResult } from '@vben/request';

import { requestClient } from '#/api/request';

export namespace CmtContentArticleCategoryApi {
  export interface ArticleCategory {
    id?: number;
    communityId?: number;
    merchantId?: number;
    name?: string;
    code?: string;
    parentId?: number;
    icon?: string;
    coverImage?: string;
    description?: string;
    sort?: number;
    status?: number;
    createTime?: string;
  }

  export interface ArticleCategoryPageReqVO extends PageParam {
    code?: string;
    name?: string;
    communityId?: number;
    merchantId?: number;
    status?: number;
    createTime?: string[];
  }
}

export function getArticleCategoryPage(params: CmtContentArticleCategoryApi.ArticleCategoryPageReqVO) {
  return requestClient.get<PageResult<CmtContentArticleCategoryApi.ArticleCategory>>(
    '/cmt/content-article-category/page',
    { params },
  );
}

export function getArticleCategory(id: number) {
  return requestClient.get<CmtContentArticleCategoryApi.ArticleCategory>(
    `/cmt/content-article-category/get?id=${id}`,
  );
}

export function createArticleCategory(data: CmtContentArticleCategoryApi.ArticleCategory) {
  return requestClient.post('/cmt/content-article-category/create', data);
}

export function updateArticleCategory(data: CmtContentArticleCategoryApi.ArticleCategory) {
  return requestClient.put('/cmt/content-article-category/update', data);
}

export function deleteArticleCategory(id: number) {
  return requestClient.delete(`/cmt/content-article-category/delete?id=${id}`);
}

export function deleteArticleCategoryList(ids: number[]) {
  return requestClient.delete(
    `/cmt/content-article-category/delete-list?ids=${ids.join(',')}`,
  );
}

export function exportArticleCategory(params: CmtContentArticleCategoryApi.ArticleCategoryPageReqVO) {
  return requestClient.download('/cmt/content-article-category/export-excel', { params });
}

/** 获取文章分类选项列表(用于下拉选择) */
export function getArticleCategoryOptions() {
  return requestClient.get<PageResult<CmtContentArticleCategoryApi.ArticleCategory>>(
    '/cmt/content-article-category/page',
    { params: { pageNo: -1, pageSize: 10 } },
  );
}
